<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../css/mui.min.css"/>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/general.css"/>
		<style type="text/css">
			.content{
				width: 100%;
				background-color: #F2F2F2;
				padding: 10px;
			}
			table{
				width: 100%;
				background-color: white;
			}
			tr{
				padding: 0.5em;
				
			}
			
			td{
				padding: 0.5em;
				padding-left: 1em;
			}
			.topdiv{
				width: 100%;
				padding: 0.5em;
				margin: 0.2em 0;
				background-color: white;
			}
			.topdiv>div{
				padding: 0.5em;
			}
			
			.foottr>td{
				padding: 1.5em 1em;
			}
			.contentdiv{
				
			}
			.tab1{
				margin: 0.5em 0;
			}
			
			.butdiv{
				padding: 15px;
			}
			.main{
				position: relative;
			}
			.tuidandiv{
				position: absolute;
				width: 30%;
				right: 0;
				top: -10px;
				overflow: hidden;
				transform:rotate(-20deg);
			}
			.tuidandiv>img{
				width: 100%;
			}
		</style>
	</head>



	<body>
		<header class="mui-bar mui-bar-nav hbg">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left colorw"></a>
		    <h1 class="mui-title" id="headerid">详情</h1>
		</header>
		<div class="mui-content">
		    <div class="main" id="listid">
		    	
		    	
		    	
		    </div>
		</div>
		
		
		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/req.js"></script>
		<script src="../js/muishow.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var rid = 0,
			
			order_number = '';	//单据号 用于退单
			window.onload = function(){
				mui.init();
				rid = getrequest().rid||0;
				
				mui.plusReady(function(res){
					 var view = plus.webview.currentWebview();
					 rid = view.rid||0;
				})
				console.log(rid);
				getrecord_detail()
			}
			
			function getrecord_detail(){
				var data = {
					url:"/api/product/record_detail",
					data:{
						access_token:acctoken(),
						id:rid,
					}
				}
				ajax(data,function(res){
					console.log(res);
					order_number = res.data.order_number;
					setrecord_detail(res.data)
					rid = res.data.id;
				})
				
			}
			function setrecord_detail(list){
				var str = '';
					if(list.is_refund){
						str += '<div class="tuidandiv">'+
							    '<img src="../img/tuidan.png"/>'+
							    '</div>';
					}
					str += '<table class="tab1" border="0" cellspacing="10" cellpadding="10">'+
					'<tr colspan="2"><td colspan="2" class="textc">'+list.do_type+'</td></tr>'+
		    		'<tr><td>日期</td><td class="border-b">'+
		    		list.createtime+
		    		'</td></tr>'+
		    		'<tr ><td>操作人</td><td class="border-b">'+list.employee_name+'</td></tr>';
		    		if(list.do_type == "调拨"){
		    			str += '<tr ><td>调入店</td><td class="border-b">'+list.to_store_name+'</td></tr>';
		    		}
		    		if(list.do_type == "入库"){
		    			str += '<tr ><td>供应商</td><td class="border-b">'+list.supplier+'</td></tr>';
		    		}
		    		
		    		
		    		str += '<tr class="border-b"><td>备注</td><td>'+list.remark+'</td></tr>'+
		    		'</table>'+
		    		'<table border="0" cellspacing="10" cellpadding="10">';
		    		var nums = 0,prices = 0;
		    		for(var i = 0; i < list.record.length; i++){
		    			str += '<tr><td>'+
		    			list.record[i].product_name+
		    			'</td><td></td><td></td></tr>'+
			    		'<tr class="border-b"><td>价格：'+
			    		list.record[i].price+
			    		'</td><td>数量：'+
			    		list.record[i].count+
			    		'</td><td>总价：'+
			    		parseFloat(list.record[i].price*list.record[i].count)+
			    		'</td></tr>';
		    			nums +=list.record[i].count;
		    			prices += parseFloat(list.record[i].price*list.record[i].count);
		    		}
		    		str += '<tr class="foottr"><td>合计</td><td>数量：'+
		    		nums+
		    		'</td><td>总价：'+
		    		prices+
		    		'</td></tr></table>';
		    		
		    		str += '<div class="butdiv">'+
		    				'<button type="button" onclick="refund_order()" class="mui-btn mui-btn-blue mui-btn-block">退单</button>'+
		    				'</div>'
				g("listid").innerHTML = str;
			}
			
			
			function refund_order(){
				mui.confirm("是否确认退单？","",["取消","确定"],function(e){
					if(e.index == 1){
						console.log("退单");
						var data = {
							url:"/api/product/refund",
							data:{
								access_token:acctoken(),
								//order_number:order_number,
								record_id:rid,
							}
						}
						ajax(data,function(res){
							console.log(res);
							mui.toast(res.msg);
							//getrecord_detail();
							setTimeout(function(){
								var pPage = plus.webview.currentWebview();
								var oPage = pPage.opener();
								oPage.evalJS("onshow();");
								mui.back();
							},300)
						})
						
					}
					
				})
				
			}
			
			
		</script>
	</body>

</html>